﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Player
/// </summary>
public class Player
{
    private string _name;
    private IList<Card> _hand = new List<Card>();
    private readonly IList<CardCombos> _combos;
    public string Name { get { return _name; } }

    public Player(string name)
    {
        _name = name;
    }

    public void addCardToHand(Card card)
    {
        _hand.Add(card);
    }

    public Boolean hasCard(CardRank rank)
    {
        return _hand.Any(c => c.Rank == rank);
    }

    public IEnumerable<Card> removeCardFromHand(CardRank rank)
    {
        var cards = _hand.TakeWhile(c => c.Rank == rank);

        if (cards.Count() == 0)
        {
            //TODO what to do here
        }

        _hand = (IList<Card>)_hand.Except(cards);
        return cards;
    }

    public IEnumerable<CardRank> PullOutBooks()
    {
        List<CardRank> books = new List<CardRank>();
        for (int i = 1; i <= 13; i++)
        {
            CardRank rank = (CardRank)i;
            int howMany = 0;
            if (hasCard(rank))
            {
                howMany = _hand.Where(c => c.Rank == rank).Count();
            }
            
            if (howMany == 4)
            {
                books.Add(rank);
                removeCardFromHand(rank);
            }
        }
        return books;
    }

    public List<Card> GetCardNames() { return _hand.ToList(); }
    public int CardCount { get { return _hand.Count; } }


}